package com.wq.jdk8;

import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

/**
 * @Author: wangqiang20995
 * @Date:2019/3/8
 * @Description:
 * @Resource:
 */
public class HasMapDemo {

    public static class Demo{
        private String name;
        private String address;

        public String getName() {
            return name;
        }
        public Demo(){}

        public Demo(String name, String address) {
            this.name = name;
            this.address = address;
        }

        public void setName(String name) {
            this.name = name;
        }

        public String getAddress() {
            return address;
        }

        public void setAddress(String address) {
            this.address = address;
        }

        @Override
        public boolean equals(Object o) {
            if (this == o) {return true;}
            if (!(o instanceof Demo)) {return false;}
            Demo demo = (Demo) o;
            return Objects.equals(name, demo.name) &&
                    Objects.equals(address, demo.address);
        }

        @Override
        public int hashCode() {

            return Objects.hash(name, address);
        }
    }

    public static void main(String[] args){
        Demo demo = new Demo();
        demo.setName("a");
        demo.setAddress("add");

        Map<Demo,String> map = new HashMap<>();
        map.put(demo,"12321");

        System.out.println(map.get(new Demo("a","add")));
    }
}
